package com.ljkj.cordial.chat.ui.views;

import com.lanjiu.lib.imclient.bus.EventConstants;
import com.lanjiu.lib.imclient.bus.MessageEvent;
import com.lanjiu.lib.imclient.dto.GroupVo;
import com.lanjiu.lib.imclient.dto.base.Dto;
import com.lanjiu.lib.imclient.ims.IMSContacts;
import com.lanjiu.lib.imclient.user.UserPreferences;
import com.lanjiu.lib.utils.log.Logger;
import com.ljkj.cordial.chat.ui.IView;

/**
 * @description:
 * @author: Panwei
 * @date: 2020/2/19 17:30
 */
public class GroupMemberAtelView extends IView {

    private GroupMemberAtelCallback mCallback;

    public GroupMemberAtelView(GroupMemberAtelCallback mCallback) {
        this.mCallback = mCallback;
    }

    public void doGetGroupMemberList(String groupId) {
        int action = UserPreferences.isRegistered() ? EventConstants.Action.GROUP_INFO_REGISTERED : EventConstants.Action.GROUP_INFO_TOURISTS;
        doSendRequest(action, groupId + ";" + IMSContacts.Contact.OLD_GROUP);
    }

    @Override
    protected void onMessageEventHandle(MessageEvent event) {
        Logger.print("GroupMemberAtelView", event.toString());
        if (event.action() == EventConstants.Action.GROUP_INFO_TOURISTS
                || event.action() == EventConstants.Action.GROUP_INFO_REGISTERED) {
            GroupVo group = null;
            if (checkIsSuccess(event.code(), event.data()))
                group = Dto.fromJson(event.data(), GroupVo.class);
            if (null != mCallback)
                mCallback.onGetGroupMemberListCallback(event.code(), event.msg(), group);
        }
    }

    public interface GroupMemberAtelCallback {

        void onGetGroupMemberListCallback(int code, String msg, GroupVo data);
    }
}
